package com.hdoit.ares.web.onlineSer.wechat;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hdoit.ares.logical.official.model.Artical;
import com.hdoit.ares.logical.official.model.ArticalClassify;
import com.hdoit.ares.logical.official.service.IArticalClassifyService;
import com.hdoit.ares.logical.official.service.IArticalService;
import com.hdoit.ares.logical.viewmodel.official.ArticalClassifySearch;
import com.tennetcn.component.wechat.BaseWechat;

@Controller
@RequestMapping(value="/wechat/onlineSer/onlineSer/")
public class OnlineSerWechat extends BaseWechat{

	@Override
	public String getRoutePath() {
		return "areas/wechat/onlineSer/onlineSer/";
	}
	
	private IArticalClassifyService articalClassifyService;
	public IArticalClassifyService getArticalClassifyService() {
		return articalClassifyService;
	}
	@Resource
	public void setArticalClassifyService(IArticalClassifyService articalClassifyService) {
		this.articalClassifyService = articalClassifyService;
	}

	private IArticalService articalService;
	public IArticalService getArticalService() {
		return articalService;
	}
	@Resource
	public void setArticalService(IArticalService articalService) {
		this.articalService = articalService;
	}

	private final String onlineSerViewName="onlineSer";
	private final String onlineSerDetailViewName="onlineSerDetail";
	private final String onlineQuestionViewName="onlineQuestion";
	
	@RequestMapping(value = onlineSerViewName, method = { RequestMethod.GET,RequestMethod.POST },produces = "text/plain;charset=utf-8")
	public String onlineSer(Model model){
//		查询类型为菜单父级为在线客服的所有列表
		/*String type="menu";
		String parentId="a2217577-7fe1-46ca-a716-819f02341a84";*/
		String url="areas/wechat/onlineSer/onlineSer";
		ArticalClassifySearch search=new ArticalClassifySearch();
		search.setFunctionURL(url);
		ArticalClassify articalClassify=articalClassifyService.queryModel(search);
		String type="menu";
		String parentId=null;
		if(articalClassify!=null){ 
			 parentId=articalClassify.getId();
		}
		
		List<ArticalClassify> articalClassifys=articalClassifyService.queryOnlineSerList(type, parentId);
		
		model.addAttribute("articalClassifys",articalClassifys);
		
		return view(onlineSerViewName);
	}
	
	@RequestMapping(value = onlineSerDetailViewName, method = { RequestMethod.GET,RequestMethod.POST },produces = "text/plain;charset=utf-8")
	public String onlineSerDetail(Model model,String typeId){

		List<Artical> articals=articalService.queryListArtical(typeId);
		
		model.addAttribute("articals",articals);
		
		return view(onlineSerDetailViewName);
	}
	
	@RequestMapping(value = onlineQuestionViewName, method = { RequestMethod.GET,RequestMethod.POST },produces = "text/plain;charset=utf-8")
	public String onlineQuestion(Model model,String id){

		Artical artical=articalService.queryArticalById(id);
		
		model.addAttribute("artical",artical);
		
		return view(onlineQuestionViewName);
	}
}
